<template>
<div class="app-container">
<el-tabs
    v-model="activeName"
    type="card"
    class="demo-tabs"
    @tab-click="handleClick"
    
  >
    <el-tab-pane label="入库统计" name="first">
      <!-- 入库统计 -->
      <div >
    <!-- <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="入库单号" prop="warehousingOrderId">
        <el-input
          v-model="queryParams.warehousingOrderId"
          placeholder="请输入入库单号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="入库日期" style="width: 308px">
        <el-date-picker
          v-model="daterangeWarehousingDate"
          value-format="YYYY-MM-DD"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="入库类型" prop="warehousingType" style="width: 200px">
        <el-select v-model="queryParams.warehousingType" placeholder="请选择入库类型" clearable>
          <el-option
            v-for="dict in doctor_drug_category"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="供应商" prop="supplier" style="width: 200px">
        <el-select v-model="queryParams.supplier" placeholder="请选择供应商" clearable>
          <el-option
            v-for="dict in doctor_drug_manufacturer"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form> -->

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          :disabled="multiple"
          @click="handleAdd"
          v-hasPermi="['ywx:Inventory:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['ywx:Inventory:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['ywx:Inventory:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['ywx:Inventory:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="InventoryList" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="入库单号" align="center" prop="warehousingOrderId" />
      <!-- <el-table-column label="入库单号" align="center" prop="warehousingOrderId">
        <template #default="scope">
          <span @click="getInventory(scope.row.warehousingOrderId)">{{ scope.row.warehousingOrderId }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="入库日期" align="center" prop="warehousingDate" width="140">
        <template #default="scope">
          <span>{{ parseTime(scope.row.warehousingDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="入库药品分类" align="center" prop="warehousingStaff" width="120">
        <template #default="scope">
          <dict-tag :options="doctor_drug_category" :value="scope.row.warehousingStaff"/>
        </template>
      </el-table-column>      
      <el-table-column label="入库类型" align="center" prop="warehousingType"/>
      <el-table-column label="供应商" align="center" prop="supplier">
        <template #default="scope">
          <dict-tag :options="doctor_drug_manufacturer" :value="scope.row.supplier"/>
        </template>
      </el-table-column>
      <el-table-column label="制单日期" align="center" prop="documentCreationDate" width="140">
        <template #default="scope">
          <span>{{ parseTime(scope.row.documentCreationDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="制单人员" align="center" prop="documentCreationStaff" />
      <!-- <el-table-column label="备注" align="center" prop="remarks" /> -->
      <el-table-column label="采购金额" align="center" prop="totalPurchaseAmount" />
      <el-table-column label="零售金额" align="center" prop="totalRetailAmount" />
      <!-- <el-table-column label="审核状态" align="center" prop="auditStatus">
        <template #default="scope">
          <dict-tag :options="sys_supplier_management" :value="scope.row.auditStatus"/>
        </template>
      </el-table-column> -->
      <el-table-column label="审核日期" align="center" prop="auditDate" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.auditDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核人员" align="center" prop="auditStaff" />
      <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['ywx:Inventory:edit']">修改</el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['ywx:Inventory:remove']">删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

  
      </div>
    </el-tab-pane>
    <el-tab-pane label="出库统计" name="second">
      <!-- 出库统计 -->
      <div class="app-container">
        <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          :disabled="multiple"
          @click="handleAdd"
          v-hasPermi="['ywx:Inventory:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['ywx:Inventory:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['ywx:Inventory:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['ywx:Inventory:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
        <el-table v-loading="loading" :data="outIntermediateList" @selection-change="handleSelectionChange">
          <!-- <el-table-column type="selection" width="55" align="center" /> -->
          <el-table-column label="序号" align="center" prop="id" />
          <el-table-column label="订单号id" align="center" prop="drugsOutId" />
          <el-table-column label="药品编码" align="center" prop="drugCode" />
          <!-- 遍历 drugList 当前的药品编码和药品列表中的药品编码一致时，显示药品名称  -->
          <el-table-column label="药品名称" align="center">
              <template #default="scope">
                {{drugList.find(item => item.drugCode === scope.row.drugCode)?.drugGenericName}}
              </template>
          </el-table-column>
          <el-table-column label="生产厂家" align="center">
              <template #default="scope">
                <dict-tag :options="doctor_drug_manufacturer" :value='drugList.find(item => item.drugCode === scope.row.drugCode)?.drugManufacturer'/>
              </template>
          </el-table-column>
          <el-table-column label="规格" align="center">
            <template #default="scope">
              {{drugList.find(item => item.drugCode === scope.row.drugCode)?.drugSpecification}}
            </template>
          </el-table-column>
          <el-table-column label="出库类型" align="center" prop="drugsOut.drugsOutType" />
          <el-table-column label="数量" align="center" prop="quantity" />
          <el-table-column label="单位" align="center" prop="unit">
            <template #default="scope">
              <dict-tag :options="doctor_packaging_unit" :value="scope.row.unit"/>
            </template>
          </el-table-column>
          <el-table-column label="采购价(元)" align="center">
              <template #default="scope">
                {{drugList.find(item => item.drugCode === scope.row.drugCode)?.purchasePrice}}
              </template>
          </el-table-column>
          
          <el-table-column label="采购金额(元)" align="center" prop="purchaseAmount">
              <template #default="scope">
                {{ (scope.row.quantity * drugList.find(item => item.drugCode === scope.row.drugCode)?.purchasePrice).toFixed(2) }}
              </template>
            </el-table-column>
            
            <el-table-column label="利润(元)" align="center">
              <template #default="scope">
                {{ ((drugList.find(item => item.drugCode === scope.row.drugCode)?.retailPrice - drugList.find(item => item.drugCode === scope.row.drugCode)?.purchasePrice) * scope.row.quantity).toFixed(2) }}
              </template>
            </el-table-column>
            <el-table-column label="出库人员" align="center" prop="drugsOut.drugsOutCreationStaff" />
            <el-table-column label="出库日期" align="center" prop="drugsOut.drugsOutDate" width="180">
              <template #default="scope">
                <span>{{ parseTime(scope.row.drugsOut.auditDate, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="审核人员" align="center" prop="drugsOut.auditStaff" />
            <el-table-column label="审核日期" align="center" prop="drugsOut.auditDate" width="180">
              <template #default="scope">
                <span>{{ parseTime(scope.row.drugsOut.auditDate, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
        </el-table>
        <div style="padding: 20px;">
            采购金额合计：<text style="color: red;font-weight: 700;font-size: large;margin: 0 5px;">{{ totalPurchaseAmount }}</text>元 
            利润合计：<text style="color: red;font-weight: 700;font-size: large;margin: 0 5px;">{{ totalProfit }}</text>元
        </div>
      </div>
    </el-tab-pane>
    <!-- <el-tab-pane label="进销存统计" name="third">进销存统计</el-tab-pane> -->
    <el-tab-pane label="药品销售明细" name="sixth">
      <!-- 药品销售明细 -->
      <div class="app-container">
        <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          :disabled="multiple"
          @click="handleAdd"
          v-hasPermi="['ywx:Inventory:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['ywx:Inventory:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['ywx:Inventory:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['ywx:Inventory:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
        <el-table v-loading="loading" :data="outIntermediateList" @selection-change="handleSelectionChange">
          <!-- <el-table-column type="selection" width="55" align="center" /> -->
          <el-table-column label="序号" align="center" prop="id" />
          <el-table-column label="订单号id" align="center" prop="drugsOutId" />
          <el-table-column label="药品编码" align="center" prop="drugCode" />
          <!-- 遍历 drugList 当前的药品编码和药品列表中的药品编码一致时，显示药品名称  -->
          <el-table-column label="药品名称" align="center">
              <template #default="scope">
                {{drugList.find(item => item.drugCode === scope.row.drugCode)?.drugGenericName}}
              </template>
          </el-table-column>
          <el-table-column label="生产厂家" align="center">
              <template #default="scope">
                <dict-tag :options="doctor_drug_manufacturer" :value='drugList.find(item => item.drugCode === scope.row.drugCode)?.drugManufacturer'/>
              </template>
          </el-table-column>
          <el-table-column label="规格" align="center">
            <template #default="scope">
              {{drugList.find(item => item.drugCode === scope.row.drugCode)?.drugSpecification}}
            </template>
          </el-table-column>
          <el-table-column label="数量" align="center" prop="quantity" />
          <el-table-column label="单位" align="center" prop="unit">
            <template #default="scope">
              <dict-tag :options="doctor_packaging_unit" :value="scope.row.unit"/>
            </template>
          </el-table-column>
          <el-table-column label="采购价(元)" align="center">
              <template #default="scope">
                {{drugList.find(item => item.drugCode === scope.row.drugCode)?.purchasePrice}}
              </template>
          </el-table-column>
          <el-table-column label="零售价(元)" align="center">
              <template #default="scope">
                {{drugList.find(item => item.drugCode === scope.row.drugCode)?.retailPrice}}
              </template>
          </el-table-column>
          <el-table-column label="采购金额(元)" align="center" prop="purchaseAmount">
              <template #default="scope">
                {{ (scope.row.quantity * drugList.find(item => item.drugCode === scope.row.drugCode)?.purchasePrice).toFixed(2) }}
              </template>
            </el-table-column>
            <el-table-column label="零售金额(元)" align="center" prop="retailAmount">
              <template #default="scope">
                {{ (scope.row.quantity * drugList.find(item => item.drugCode === scope.row.drugCode)?.retailPrice).toFixed(2) }}
              </template>
            </el-table-column>
            <el-table-column label="利润(元)" align="center">
          <template #default="scope">
            {{ ((drugList.find(item => item.drugCode === scope.row.drugCode)?.retailPrice - drugList.find(item => item.drugCode === scope.row.drugCode)?.purchasePrice) * scope.row.quantity).toFixed(2) }}
          </template>
        </el-table-column>
        </el-table>
        <div style="padding: 20px;">
            采购金额合计：<text style="color: red;font-weight: 700;font-size: large;margin: 0 5px;">{{ totalPurchaseAmount }}</text>元 
            零售金额合计：<text style="color: red;font-weight: 700;font-size: large;margin: 0 5px;">{{ totalRetailAmount }}</text>元
            利润合计：<text style="color: red;font-weight: 700;font-size: large;margin: 0 5px;">{{ totalProfit }}</text>元
        </div>
      </div>
    </el-tab-pane>
    <el-tab-pane label="处方药品排行" name="seven">
      <!-- 药品排行 -->
      <div class="app-container">
        <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          :disabled="multiple"
          @click="handleAdd"
          v-hasPermi="['ywx:Inventory:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['ywx:Inventory:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['ywx:Inventory:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['ywx:Inventory:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
        <el-table v-loading="loading" :data="outIntermediate" @selection-change="handleSelectionChange">
          <!-- <el-table-column type="selection" width="55" align="center" /> -->
          <el-table-column label="序号" align="center" prop="id" />
          <!-- <el-table-column label="入库订单号id" align="center" prop="drugsOutId" /> -->
          <el-table-column label="药品编码" align="center" prop="drugCode" />
          <!-- 遍历 drugList 当前的药品编码和药品列表中的药品编码一致时，显示药品名称  -->
          <el-table-column label="药品名称" align="center">
              <template #default="scope">
                {{drugList.find(item => item.drugCode === scope.row.drugCode)?.drugGenericName}}
              </template>
          </el-table-column>
          <el-table-column label="生产厂家" align="center">
              <template #default="scope">
                <dict-tag :options="doctor_drug_manufacturer" :value='drugList.find(item => item.drugCode === scope.row.drugCode)?.drugManufacturer'/>
              </template>
          </el-table-column>
          <el-table-column label="数量" align="center" prop="quantity" />
          <el-table-column label="单位" align="center" prop="unit">
            <template #default="scope">
              <dict-tag :options="doctor_packaging_unit" :value="scope.row.unit"/>
            </template>
          </el-table-column>
          <!-- <el-table-column label="采购价(元)" align="center">
              <template #default="scope">
                {{drugList.find(item => item.drugCode === scope.row.drugCode)?.purchasePrice}}
              </template>
          </el-table-column> -->
          <el-table-column label="零售价(元)" align="center">
              <template #default="scope">
                {{drugList.find(item => item.drugCode === scope.row.drugCode)?.retailPrice}}
              </template>
          </el-table-column>
          <!-- <el-table-column label="采购金额(元)" align="center" prop="purchaseAmount">
              <template #default="scope">
                {{ (scope.row.quantity * drugList.find(item => item.drugCode === scope.row.drugCode)?.purchasePrice).toFixed(2) }}
              </template>
            </el-table-column> -->
            <el-table-column label="零售金额(元)" align="center" prop="retailAmount">
              <template #default="scope">
                {{ (scope.row.quantity * drugList.find(item => item.drugCode === scope.row.drugCode)?.retailPrice).toFixed(2) }}
              </template>
            </el-table-column>
        </el-table>
        <div style="padding: 20px;">
            <!-- 采购金额合计：<text style="color: red;font-weight: 700;font-size: large;margin: 0 5px;">{{ totalPurchaseAmount }}</text>元  -->
            零售金额合计：<text style="color: red;font-weight: 700;font-size: large;margin: 0 5px;">{{ totalRetailAmount }}</text>元
        </div>
      </div>
    </el-tab-pane>
  </el-tabs>
</div>
  
</template>

<script setup name="Inventory">
import { ref } from 'vue'

const activeName = ref('first')
// const handleClick = (tab: TabsPaneContext, event: Event) => {
//   console.log(tab, event)
// }

import { listWarehousing,getWarehousing,addWarehousing,updateWarehousing,delWarehousing,listWarehousingByOrderId } from "@/api/count/Inventory";
import { listOutIntermediate, getOutIntermediate, delOutIntermediate, addOutIntermediate, updateOutIntermediate } from "@/api/drug/outIntermediate";
import { listDrug, getDrug, delDrug, addDrug, updateDrug,getDrugCode } from "@/api/drug/drug";
const { proxy } = getCurrentInstance();
const { sys_supplier_management, doctor_drug_category,doctor_drug_manufacturer,doctor_packaging_unit } = proxy.useDict('sys_supplier_management', 'doctor_drug_category','doctor_drug_manufacturer','doctor_packaging_unit');



const InventoryList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const daterangeWarehousingDate = ref([]);
const outIntermediateList = ref([]);
const outIntermediate = ref([]);
const drugList = ref([]);

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 20,
    warehousingOrderId: null,
    warehousingDate: null,
    warehousingType: null,
    supplier: null,
  },
  rules: {
    warehousingOrderId: [
      { required: true, message: "入库单号不能为空", trigger: "blur" }
    ],
    warehousingDate: [
      { required: true, message: "入库日期不能为空", trigger: "blur" }
    ],
    warehousingStaff: [
      { required: true, message: "入库人员不能为空", trigger: "change" }
    ],
    warehousingType: [
      { required: true, message: "入库类型不能为空", trigger: "change" }
    ],
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询入库统计列表 */
function getList() {
  loading.value = true;
  // queryParams.value.params = {};
  // if (null != daterangeWarehousingDate && '' != daterangeWarehousingDate) {
  //   queryParams.value.params["beginWarehousingDate"] = daterangeWarehousingDate.value[0];
  //   queryParams.value.params["endWarehousingDate"] = daterangeWarehousingDate.value[1];
  // }
  listWarehousing(queryParams.value).then(response => {
    InventoryList.value = response.rows.sort((a, b) => a.id - b.id); 
    console.log(InventoryList.value);
    total.value = response.total;
    loading.value = false;
  });
  
}
/** 查询药品入库和药品中间列表 */
function getOutIntermediateList() {
  loading.value = true;
  listOutIntermediate(queryParams.value).then(response => {
    // outIntermediateList.value = response.rows;
    // console.log(outIntermediateList.value);
    // outIntermediate.value = outIntermediateList.value.sort((a, b) => b.quantity - a.quantity);
    outIntermediateList.value = response.rows.sort((a, b) => a.drugsOutId - b.drugsOutId); // 根据订单号 id 正序排列
    outIntermediate.value = [...outIntermediateList.value].sort((a, b) => b.quantity - a.quantity); // 根据数量倒序排列
    total.value = response.total;
    loading.value = false;
  });
}
/** 查询药品信息列表 */
function getdrugList() {
  loading.value = true;
  queryParams.value.params = {};
  // if (null != daterangeCreationTime && '' != daterangeCreationTime) {
  //   queryParams.value.params["beginCreationTime"] = daterangeCreationTime.value[0];
  //   queryParams.value.params["endCreationTime"] = daterangeCreationTime.value[1];
  // }
  listDrug(queryParams.value).then(response => {
    drugList.value = response.rows;
    // console.log(drugList.value);
    total.value = response.total;
    loading.value = false;
  });
}
// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    warehousingOrderId: null,
    warehousingDate: null,
    warehousingStaff: null,
    warehousingType: null,
    supplier: null,
    documentCreationDate: null,
    documentCreationStaff: null,
    remarks: null,
    totalPurchaseAmount: null,
    totalRetailAmount: null,
    auditStatus: null,
    auditDate: null,
    auditStaff: null
  };
  proxy.resetForm("InventoryRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  daterangeWarehousingDate.value = [];
  proxy.resetForm("queryRef");
  handleQuery();
}
// 计算属性
const totalPurchaseAmount = computed(() => {
  return outIntermediateList.value.reduce((sum, item) => sum + parseFloat(item.purchaseAmount || 0), 0).toFixed(2);
});

const totalRetailAmount = computed(() => {
  return outIntermediateList.value.reduce((sum, item) => sum + parseFloat(item.retailAmount || 0), 0).toFixed(2);
});
// 计算总利润
const totalProfit = computed(() => {
  return outIntermediateList.value.reduce((sum, item) => {
    const purchasePrice = drugList.value.find(drug => drug.drugCode === item.drugCode)?.purchasePrice || 0;
    const retailPrice = drugList.value.find(drug => drug.drugCode === item.drugCode)?.retailPrice || 0;
    return sum + ((retailPrice - purchasePrice) * item.quantity);
  }, 0).toFixed(2);
});
// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加入库统计";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const _id = row.id || ids.value
  getInventory(_id).then(response => {
    form.value = response.data;
    open.value = true;
    title.value = "修改入库统计";
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["InventoryRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateInventory(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addInventory(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal.confirm('是否确认删除入库统计编号为"' + _ids + '"的数据项？').then(function() {
    return delInventory(_ids);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('count/Inventory/export', {
    ...queryParams.value
  }, `Inventory_${new Date().getTime()}.xlsx`)
}

getList();
getOutIntermediateList();
getdrugList();
</script>
<style>
/* .demo-tabs > .el-tabs__content {
  padding: 32px;
  color: #6b778c;
  font-size: 32px;
  font-weight: 600;
} */
</style>